Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail early, in modern GENERIC builds, if certain required browser functionality is missing (issue 11762) #11771

Merged
merged 1 commit into from
Apr 1, 2020

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Apr 1, 2020

With two kind of builds now being produced, with/without translation/polyfills, it's unfortunately somewhat easy for users to accidentally pick the wrong one.

In the case where a user would attempt to use a modern build of PDF.js in an older browser, such as e.g. IE11, the failure would be immediate when the code is loaded (given the use of unsupported ECMAScript features).
However in some browsers/environments, in particular Node.js, a modern PDF.js build may load correctly and thus appear to function, only to fail for e.g. certain API calls. To hopefully lessen the support burden, and to try and improve things overall, this patch adds checks to ensure that a modern build of PDF.js cannot be used in browsers/environments which lack native support for critical functionality (such as e.g. ReadableStream). Hence we'll fail early, with an error message telling users to pick an ES5-compatible build instead.

To ensure that we actually test things better especially w.r.t. usage of the PDF.js library in Node.js environments, the gulp npm-test task as used by Node.js/Travis was changed (back) to test an ES5-compatible build.
(Since the bots still test the code as-is, without transpilation/polyfills, this shouldn't really be a problem as far as I can tell.)
As part of these changes there's now both gulp lib and gulp lib-es5 build targets, similar to e.g. the generic builds, which thanks to some re-factoring only required adding a small amount of code.

Please note: While it's probably too early to tell if this will be a widespread issue, it's possible that this is the sort of patch that may warrant being git cherry-picked onto the current beta version (v2.4.456).

Fixes #11762

Much smaller/easier diff with https://github.com/mozilla/pdf.js/pull/11771/files?w=1

@Snuffleupagus
Copy link
Collaborator Author

/botio unittest

@pdfjsbot
Copy link

pdfjsbot commented Apr 1, 2020

From: Bot.io (Linux m4)


Received

Command cmd_unittest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/824b41a17f2cb54/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Apr 1, 2020

From: Bot.io (Windows)


Received

Command cmd_unittest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.215.176.217:8877/d472f857e744818/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Apr 1, 2020

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/d472f857e744818/output.txt

Total script time: 2.13 mins

  • Unit Tests: FAILED

@pdfjsbot
Copy link

pdfjsbot commented Apr 1, 2020

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/824b41a17f2cb54/output.txt

Total script time: 2.71 mins

  • Unit Tests: Passed

…unctionality is missing (issue 11762)

With two kind of builds now being produced, with/without translation/polyfills, it's unfortunately somewhat easy for users to accidentally pick the wrong one.

In the case where a user would attempt to use a modern build of PDF.js in an older browser, such as e.g. IE11, the failure would be immediate when the code is loaded (given the use of unsupported ECMAScript features).
However in some browsers/environments, in particular Node.js, a modern PDF.js build may load correctly and thus *appear* to function, only to fail for e.g. certain API calls. To hopefully lessen the support burden, and to try and improve things overall, this patch adds checks to ensure that a modern build of PDF.js cannot be used in browsers/environments which lack native support for critical functionality (such as e.g. `ReadableStream`). Hence we'll fail early, with an error message telling users to pick an ES5-compatible build instead.

To ensure that we actually test things better especially w.r.t. usage of the PDF.js library in Node.js environments, the `gulp npm-test` task as used by Node.js/Travis was changed (back) to test an ES5-compatible build.
(Since the bots still test the code as-is, without transpilation/polyfills, this shouldn't really be a problem as far as I can tell.)
As part of these changes there's now both `gulp lib` and `gulp lib-es5` build targets, similar to e.g. the generic builds, which thanks to some re-factoring only required adding a small amount of code.

*Please note:* While it's probably too early to tell if this will be a widespread issue, it's possible that this is the sort of patch that *may* warrant being `git cherry-pick`ed onto the current beta version (v2.4.456).
@Snuffleupagus Snuffleupagus changed the title Fail early, in modern GENERIC builds, if certain required polyfills are missing (issue 11762) Fail early, in modern GENERIC builds, if certain required browser functionality is missing (issue 11762) Apr 1, 2020
@timvandermeij timvandermeij merged commit 7ed71a0 into mozilla:master Apr 1, 2020
@timvandermeij
Copy link
Contributor

Looks like a good change to me; thanks! Note that the Travis CI build did run and pass, but for some reason it's not visible on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Node support broken in 2.4.456 due to missing ReadableStream
3 participants